package com.usooft.metaTalent.core.system.service.basic;

import com.usooft.metaTalent.core.system.entity.SearchTerm;
import com.usooft.metaTalent.core.system.service.SearchTermService;
import com.usooft.metaTalent.core.system.service.base.BaseSearchTermService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

@Service
@RequiredArgsConstructor
public class BasicSearchTermService extends BaseSearchTermService implements SearchTermService {

    @Override
    @Transactional
    public void edit(SearchTerm searchTerm, String content, Boolean isHot, Boolean isTop, SearchTerm.Position position, SearchTerm.PortType portType, Integer sort) {
        Assert.isTrue(StringUtils.isNotBlank(content), "搜索词条内容不能为空");
        Assert.isTrue(sort != null && sort > 0, "排序不能为空,并且大于0");
        Assert.isTrue(position != null, "搜索词条位置不能为空");
        Assert.isTrue(portType != null, "搜索词条端口不能为空");
        Assert.isTrue(isHot != null, "是否热门不能为空");
        Assert.isTrue(isTop != null, "是否置顶不能为空");
        searchTerm.setContent(content);
        searchTerm.setIsHot(isHot);
        searchTerm.setIsTop(isTop);
        searchTerm.setPosition(position);
        searchTerm.setPortType(portType);
        searchTerm.setSort(sort);
        this.internalUpdate(searchTerm);
    }

    @Override
    @Transactional
    public void create(String content, Boolean isHot, Boolean isTop, SearchTerm.Position position, SearchTerm.PortType portType, Integer sort) {
        Assert.isTrue(StringUtils.isNotBlank(content), "搜索词条内容不能为空");
        Assert.isTrue(sort != null && sort > 0, "排序不能为空,并且大于0");
        Assert.isTrue(position != null, "搜索词条位置不能为空");
        Assert.isTrue(portType != null, "搜索词条端口不能为空");
        Assert.isTrue(isHot != null, "是否热门不能为空");
        Assert.isTrue(isTop != null, "是否置顶不能为空");
        this.internalAdd(content, isHot, portType, position, isTop, sort);
    }
}
